#########################
##MAIN DOCUMENT FIGURES##
#########################

superpose.eb <-
function (x, y, ebl, ebu = ebl, length = 0.08, ...)
    arrows(x, y + ebu, x, y - ebl, angle = 90, code = 3,
    length = length, ...) 

##Values for Figure 2
correcttot = matrix(c(
0.725,	0.607,	0.493,	0.536,
0.094,	0.156,	0.381,	0.341,
0.111,	0.180,	0.075,	0.073,
0.070,	0.057,	0.052,	0.050	
),4,4)

rownames(correcttot)=c(
".00-.18 Ex-Ante Conflict",
".32-.34 Ex-Ante Conflict",
".55-.70 Ex-Ante Conflict",
".82-.85 Ex-Ante Conflict")

colnames(correcttot)=c("Both Right","Only Initial Right","Only Signal Right","Both Wrong")

correcttot

correcttot.lb = matrix(c(
0.654,	0.485,	0.425,	0.438,
0.048,	0.080,	0.310,	0.252,
0.058,	0.088,	0.044,	0.028,
0.025,	0.006,	0.026,	0.007	
),4,4)

correcttot.eb=correcttot-correcttot.lb

##Values for Figure 3
   diff<-c(0.122,0.140,	0.182,	0.218,	0.222,	0.252,	0.253,	0.252,	0.243,	0.241,	0.239)
diff.se<-c(0.153,0.147,	0.127,	0.106,	0.104,	0.080,	0.075,	0.074,	0.075,	0.076,	0.076)
   same<-c(0.033,0.029,	0.018,	0.006,	0.004,	-0.019,	-0.036,	-0.039,	-0.057,	-0.059,	-0.062)
same.se<-c(0.039,0.038,	0.034,	0.032,	0.032,	0.032,	0.039,	0.040,	0.055,	0.058,	0.061)

conflict<-c(0.000,0.052,0.184,0.319,0.336,0.551,0.686,0.703,0.821,0.837,0.854)

adjust=.002

##Values for Figure 4
   correctchoice<-c(0.087,0.074,0.039,-0.001,-0.006,-0.077,-0.127,-0.134,-0.181,-0.187,-0.194)
correctchoice.se<-c(0.052,0.049,0.041, 0.036, 0.035, 0.035, 0.042, 0.043, 0.055, 0.056, 0.058)


##FIGURE 2
jpeg(filename="initialvssignal.jpg",width=1200,height=700)
par(oma=c(1,2,0,0))
x.abscis <- barplot(correcttot, beside=TRUE,space=c(0,.15),col=c("grey90","grey65","grey40","grey15"), ylim=c(0,.8),ylab=" ",cex.names=2.3,cex.axis=1.5)
superpose.eb(x.abscis, correcttot, correcttot.eb, col=1, lwd=2) 
mtext("Proportion of Subjects",side=2,line=3,cex=2.4)
legend(10,.6,legend=c(
".00-.18 Ex-Ante Conflict",
".32-.34 Ex-Ante Conflict",
".55-.70 Ex-Ante Conflict",
".82-.85 Ex-Ante Conflict")
,fill=c("grey90","grey65","grey40","grey15"),cex=2,bty = "n",horiz=F)

dev.off()

##FIGURE 3
jpeg(filename="followsignal.jpg",width=1000,height=700)

par(oma=c(1,2.5,0,0))
plot(conflict, diff, type = "n", axes = F, xlab = "", ylab = "", pch = 19, cex = 1.75,
    ylim = c(-.2,.5), xlim = c(0,.9), xaxs = "r", main = "")
abline(0,0,lty=2,lwd=1)

segments(conflict-adjust,diff-1.96*diff.se, 
         conflict-adjust,diff+1.96*diff.se, lwd =  1,col="grey0")
segments(conflict-adjust,diff-1.64*diff.se, 
         conflict-adjust,diff+1.64*diff.se, lwd =  3,col="grey0")
points(conflict-adjust, diff,pch=21,cex=1.8,bg = "grey0", col = "grey0")
lines(conflict-adjust, diff,col = "grey0",lwd=2,lty=1)

segments(conflict+adjust,same-1.96*same.se, 
         conflict+adjust,same+1.96*same.se, lwd =  1,col="grey60")
segments(conflict+adjust,same-1.64*same.se, 
         conflict+adjust,same+1.64*same.se, lwd =  3,col="grey60")
points(conflict+adjust, same,pch=22,cex=1.8,bg = "grey60", col = "grey60")
lines(conflict+adjust, same,col = "grey60",lwd=2,lty=1)

axis(1, seq(0,.9, by = .1), label = seq(0,.9, by = .1), las = 1, tick = T, cex.axis =1.2)#add y-axis and labels; las = 1 makes labels perpendicular to y-axis
axis(2,at = seq(-.2,.5, by = .1), label = seq(-.2,.5, by = .1), mgp = c(.8,2,1), cex.axis = 1.2)#add x-axis and labels; "pretty" creates a sequence of  equally spaced nice values that cover the range of the values in 'x'-- in this case, integers

mtext("Marginal Effect of Woman Receiver",side=2,line=.5,cex=2,outer=TRUE)
mtext("Ex-Ante Probability of Conflict",side=1,line=3.5,cex=2,outer=FALSE)
legend(.2,-.075,legend=c("Signal Different from Initial Choice","Signal Same as Initial Choice"),
pt.bg=c("grey0","grey60"),col=c("grey0","grey60"),pch=c(21,22),cex=2,bty = "n",horiz=F,lwd=2,lty=1)

dev.off()

##FIGURE 4
jpeg(filename="correctchoice.jpg",width=1000,height=900)

par(oma=c(1,2.5,0,0))
plot(conflict, correctchoice, type = "n", axes = F, xlab = "", ylab = "", pch = 19, cex = 1.75,
    ylim = c(-.4,.2), xlim = c(0,.9), xaxs = "r", main = "")
abline(0,0,lty=2,lwd=1)

segments(conflict,correctchoice-1.96*correctchoice.se, 
         conflict,correctchoice+1.96*correctchoice.se, lwd =  1,col="grey0")
segments(conflict,correctchoice-1.64*correctchoice.se, 
         conflict,correctchoice+1.64*correctchoice.se, lwd =  3,col="grey0")
points(conflict, correctchoice,pch=21,cex=1.8,bg = "grey0", col = "grey0")
lines(conflict, correctchoice,col = "grey0",lwd=1,lty=1)

axis(1, seq(0,.9, by = .1), label = seq(0,.9, by = .1), las = 1, tick = T, cex.axis =1.2)#add y-axis and labels; las = 1 makes labels perpendicular to y-axis
axis(2,at = seq(-.4,.2, by = .1), label = seq(-.4,.2, by = .1), mgp = c(.8,2,1), cex.axis = 1.2)#add x-axis and labels; "pretty" creates a sequence of  equally spaced nice values that cover the range of the values in 'x'-- in this case, integers

mtext("Marginal Effect of Woman Receiver",side=2,line=.5,cex=2,outer=TRUE)
mtext("Ex-Ante Probability of Conflict",side=1,line=3.5,cex=2,outer=FALSE)

dev.off()

#########################
##APPENDIX FIGURES##
#########################

setwd("C:/Users/John/Dropbox/Gender Influence/PSRM/Final/Appendix")

##Appendix 2 Figure 1 Values
all<-c(106.93, 91.14, 82.14, 76.93, 76.79, 82.43, 73.71, 60.43, 60.00, 71.71, 62.29, 63.93, 62.36, 60.64, 57.86)
usa<-c( 71.20, 66.20, 55.60, 47.20, 45.40, 49.60, 48.00, 42.80, 37.20, 53.80, 38.40, 48.20, 44.00, 40.60, 38.00)
ger<-c(126.78,105.00, 96.89, 93.44, 94.22,100.67, 88.00, 70.22, 72.67, 81.67, 75.56, 72.67, 72.56, 71.78, 68.89)

period=seq(1,15,by=1)

##Appendix 4 Figure 2 Values
##Values for Figure 2
truth.turnout = matrix(c(
.54412,.34031,
.50964,.54496,
.38172,.56793
),2,3)

rownames(truth.turnout)=c("Women","Men")

colnames(truth.turnout)=c("Truthful Signals","Informed Turnout","Uninformed Turnout")

truth.turnout

truth.turnout.lb = matrix(c(
.41999,.21891,
.40497,.44800,
.28172,.44843
),2,3)

truth.turnout.eb=truth.turnout-truth.turnout.lb


##Appendix 5 Figure 3 Values
   credible<-c(8.431,7.051,3.547,-0.036,-0.487,-6.193,-9.776,-10.227,-13.359,-13.784,-14.235)
credible.se<-c(5.518,5.161,4.327, 3.639, 3.569, 3.165, 3.426,  3.485,  4.014,  4.100,  4.193)

   ignore<-c(6.696,5.501,2.469,-0.633,-1.023,-5.963,-9.064,-9.455,-12.166,-12.534,-12.924)
ignore.se<-c(3.874,3.617,3.071, 2.748, 2.729, 2.945, 3.445, 3.522,  4.115,  4.202,  4.295)


##Appendix 5 Figure 4 Values
   fcredev<-c(10.990,	9.170,	4.552,	-0.170,	-0.765,	-8.287,	-13.010,-13.605,-17.733,-18.292,-18.887)
fcredev.se<-c(2.942,	2.732,	2.288,	2.035,	2.023,	2.253,	2.693,	2.759,	3.261,	3.334,	3.412)

   mcredev<-c(2.559,	2.119,	1.005,	-0.135,	-0.278,	-2.094,	-3.234,	-3.377,	-4.373,	-4.509,	-4.652)
mcredev.se<-c(4.669,	4.380,	3.678,	3.024,	2.949,	2.229,	2.117,	2.127,	2.330,	2.374,	2.424)

   fignoreev<-c(-0.4672,-1.5171,-4.1822,-6.9079,-7.2512, -11.5921,-14.3178,-14.6611,-17.0436, -17.3666,-17.7098)
fignoreev.se<-c( 2.9795, 2.7681, 2.3231, 2.0724, 2.0599,  2.2959,  2.7404,   2.8069,  3.3131,   3.3866,  3.4657)
   mignoreev<-c(-7.1631,-7.0184,-6.6509,-6.2751,-6.2278, -5.6293, -5.2534,  -5.2061, -4.8776,  -4.8331,	-4.7858)
mignoreev.se<-c(2.4877, 2.3403, 2.0225, 1.8158, 1.8006,  1.8464,  2.0815,   2.1198,  2.4264,   2.4726,  2.5226)


##Appendix 8 Figure 5 Values
AJPS = matrix(c(
.8814,.8018,
.9030,.7756,
.8557,.8328
),2,3)

rownames(AJPS)=c("Initial Choice","Actual Vote")
colnames(AJPS)=c("All Subjects","Women","Men")

AJPS

AJPS.lb = matrix(c(
.8574,.7675,
.8731,.7246,
.8195,.79099
),2,3)

AJPS.eb=AJPS-AJPS.lb


##APPENDIX 2 FIGURE 1
jpeg(filename="time.jpg",width=1500,height=900)

par(oma=c(1,2.5,0,0))
plot(period,all,ylim=c(0,130),type="n",xlab=" ",ylab=" ",axes=F)
lines(period,ger,pch=21,col="red",lwd=2)
points(period,ger,pch=21,bg="gold",col="red",cex=1.5)

lines(period,usa,pch=21,col="blue",lwd=2)
points(period,usa,pch=21,bg="red",col="blue",cex=1.5)

lines(period,all,pch=21,col="black",lwd=2)
points(period,all,pch=21,bg="black",col="black",cex=1.5)

axis(2, seq(0,130, by = 10), label = seq(0,130, by = 10), las = 1, tick = T, cex.axis =1.2)#add y-axis and labels; las = 1 makes labels perpendicular to y-axis
axis(1,at = seq(1,15, by = 1), label = seq(1,15, by = 1), mgp = c(.8,2,1), cex.axis = 1.2)#add x-axis and labels; "pretty" creates a sequence of  equally spaced nice values that cover the range of the values in 'x'-- in this case, integers

mtext("Period",side=1,line=4,cex=2,outer=FALSE)
mtext("Average Time for Period Completion in Seconds",side=2,line=4,cex=2,outer=FALSE)

legend(1,40,legend=c("All Sessions","Germany","USA"),
pt.bg=c("black","gold","red"),pch=21,col=c("black","red","blue"),lwd=2,
cex=2,bty = "n",horiz=F)

dev.off()

##APPENDIX 4 FIGURE 2
jpeg(filename="genderdifferences.jpg",width=1200,height=700)
par(oma=c(1,2,0,0))
x.abscis <- barplot(truth.turnout, beside=TRUE,space=c(0,.15),col=c("white","grey40"), ylim=c(0,1),ylab=" ",cex.names=2.3,cex.axis=1.5)
superpose.eb(x.abscis, truth.turnout, truth.turnout.eb, col=1, lwd=2) 
mtext("Proportion of Subjects",side=2,line=3,cex=2.4)
legend(0.1,1,legend=c(
"Women",
"Men")
,fill=c("white","grey40"),cex=2,bty = "n",horiz=T)


text(1.2,.75,"p=0.02", cex=1.75)
text(3.35,.75,"p=0.63", cex=1.75)
text(5.5,.75,"p=0.02", cex=1.75)


dev.off()

##APPENDIX 5 FIGURE 3

jpeg(filename="vsexante.jpg",width=1500,height=900)

par(oma=c(1,2.5,0,0),mfrow=c(1,2))
plot(conflict, credible, type = "n", axes = F, xlab = "", ylab = "", pch = 19, cex = 1.75,
    ylim = c(-25,20), xlim = c(0,.9), xaxs = "r", main = "")
abline(0,0,lty=2,lwd=1)

segments(conflict,credible-1.96*credible.se, 
         conflict,credible+1.96*credible.se, lwd =  1,col="grey0")
segments(conflict,credible-1.64*credible.se, 
         conflict,credible+1.64*credible.se, lwd =  3,col="grey0")
points(conflict, credible,pch=21,cex=1.8,bg = "grey0", col = "grey0")
lines(conflict, credible,col = "grey0",lwd=1,lty=1)

axis(1, seq(0,.9, by = .1), label = seq(0,.9, by = .1), las = 1, tick = T, cex.axis =1.2)#add y-axis and labels; las = 1 makes labels perpendicular to y-axis
axis(2,at = seq(-25,20, by = 5), label = seq(-25,20, by = 5), mgp = c(.8,2,1), cex.axis = 1.2)#add x-axis and labels; "pretty" creates a sequence of  equally spaced nice values that cover the range of the values in 'x'-- in this case, integers

mtext("Marginal Effect of Woman Receiver",side=2,line=.5,cex=2,outer=TRUE)
mtext("Credible Messenger",side=3,line=.5,cex=2,outer=FALSE)

plot(conflict, ignore, type = "n", axes = F, xlab = "", ylab = "", pch = 19, cex = 1.75,
    ylim = c(-25,20), xlim = c(0,.9), xaxs = "r", main = "")
abline(0,0,lty=2,lwd=1)

segments(conflict,ignore-1.96*ignore.se, 
         conflict,ignore+1.96*ignore.se, lwd =  1,col="grey0")
segments(conflict,ignore-1.64*ignore.se, 
         conflict,ignore+1.64*ignore.se, lwd =  3,col="grey0")
points(conflict, ignore,pch=21,cex=1.8,bg = "grey0", col = "grey0")
lines(conflict, ignore,col = "grey0",lwd=1,lty=1)

axis(1, seq(0,.9, by = .1), label = seq(0,.9, by = .1), las = 1, tick = T, cex.axis =1.2)#add y-axis and labels; las = 1 makes labels perpendicular to y-axis
axis(2,at = seq(-25,20, by = 5), label = seq(-25,20, by = 5), mgp = c(.8,2,1), cex.axis = 1.2)#add x-axis and labels; "pretty" creates a sequence of  equally spaced nice values that cover the range of the values in 'x'-- in this case, integers

mtext("Ignore Signal",side=3,line=.5,cex=2,outer=FALSE)
mtext("Ex-Ante Probability of Conflict",side=1,line=-1,cex=2,outer=TRUE)


dev.off()


##APPENDIX 5 FIGURE 4
adjustev=.005
jpeg(filename="exanteev.jpg",width=1500,height=900)

par(oma=c(1,2.5,0,0),mfrow=c(1,2))
plot(conflict, fcredev, type = "n", axes = F, xlab = "", ylab = "", pch = 19, cex = 1.75,
    ylim = c(-30,20), xlim = c(0,.9), xaxs = "r", main = "")
abline(0,0,lty=2,lwd=1)

segments(conflict-adjustev,fcredev-1.96*fcredev.se, 
         conflict-adjustev,fcredev+1.96*fcredev.se, lwd =  1,col="red")
segments(conflict-adjustev,fcredev-1.64*fcredev.se, 
         conflict-adjustev,fcredev+1.64*fcredev.se, lwd =  3,col="red")
points(conflict-adjustev, fcredev,pch=21,cex=1.8,bg = "red", col = "red")
lines(conflict-adjustev, fcredev,col = "red",lwd=1,lty=1)

segments(conflict+adjustev,mcredev-1.96*mcredev.se, 
         conflict+adjustev,mcredev+1.96*mcredev.se, lwd =  1,col="blue")
segments(conflict+adjustev,mcredev-1.64*mcredev.se, 
         conflict+adjustev,mcredev+1.64*mcredev.se, lwd =  3,col="blue")
points(conflict+adjustev, mcredev,pch=21,cex=1.8,bg = "blue", col = "blue")
lines(conflict+adjustev, mcredev,col = "blue",lwd=1,lty=1)


axis(1, seq(0,.9, by = .1), label = seq(0,.9, by = .1), las = 1, tick = T, cex.axis =1.2)#add y-axis and labels; las = 1 makes labels perpendicular to y-axis
axis(2,at = seq(-30,20, by = 5), label = seq(-30,20, by = 5), mgp = c(.8,2,1), cex.axis = 1.2)#add x-axis and labels; "pretty" creates a sequence of  equally spaced nice values that cover the range of the values in 'x'-- in this case, integers

mtext("Marginal Effect of Woman Receiver",side=2,line=.5,cex=2,outer=TRUE)
mtext("fcredev Messenger",side=3,line=.5,cex=2,outer=FALSE)

plot(conflict, ignore, type = "n", axes = F, xlab = "", ylab = "", pch = 19, cex = 1.75,
    ylim = c(-30,20), xlim = c(0,.9), xaxs = "r", main = "")
abline(0,0,lty=2,lwd=1)

segments(conflict-adjustev,fignoreev-1.96*fignoreev.se, 
         conflict-adjustev,fignoreev+1.96*fignoreev.se, lwd =  1,col="red")
segments(conflict-adjustev,fignoreev-1.64*fignoreev.se, 
         conflict-adjustev,fignoreev+1.64*fignoreev.se, lwd =  3,col="red")
points(conflict-adjustev, fignoreev,pch=21,cex=1.8,bg = "red", col = "red")
lines(conflict-adjustev, fignoreev,col = "red",lwd=1,lty=1)

segments(conflict+adjustev,mignoreev-1.96*mignoreev.se, 
         conflict+adjustev,mignoreev+1.96*mignoreev.se, lwd =  1,col="blue")
segments(conflict+adjustev,mignoreev-1.64*mignoreev.se, 
         conflict+adjustev,mignoreev+1.64*mignoreev.se, lwd =  3,col="blue")
points(conflict+adjustev, mignoreev,pch=21,cex=1.8,bg = "blue", col = "blue")
lines(conflict+adjustev, mignoreev,col = "blue",lwd=1,lty=1)
axis(1, seq(0,.9, by = .1), label = seq(0,.9, by = .1), las = 1, tick = T, cex.axis =1.2)#add y-axis and labels; las = 1 makes labels perpendicular to y-axis
axis(2,at = seq(-30,20, by = 5), label = seq(-30,20, by = 5), mgp = c(.8,2,1), cex.axis = 1.2)#add x-axis and labels; "pretty" creates a sequence of  equally spaced nice values that cover the range of the values in 'x'-- in this case, integers

mtext("Ignore Signal",side=3,line=.5,cex=2,outer=FALSE)
mtext("Ex-Ante Probability of Conflict",side=1,line=-1,cex=2,outer=TRUE)

dev.off()


##APPENDIX 8 FIGURE 5
jpeg(filename="AJPSgender.jpg",width=1200,height=700)
par(oma=c(1,2,0,0))
x.abscis <- barplot(AJPS, beside=TRUE,space=c(0,.15),col=c("white","grey40"), ylim=c(0,1),ylab=" ",cex.names=2.3,cex.axis=1.5)
superpose.eb(x.abscis, AJPS, AJPS.eb, col=1, lwd=2) 
mtext("Probability of Correct Vote",side=2,line=3,cex=2.4)

legend(0.1,1.02,legend=c("Initial Choice","Actual Vote"),fill=c("white","grey40"),cex=2,bty = "n",horiz=T)


dev.off()
